import requests
from pyquery import PyQuery as pq

# 糗事百科爬虫
def qiubaispider(url= 'https://www.qiushibaike.com/textnew/'):
    # 指定请求的浏览器标志
    headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko'}
    r = requests.get(url, headers= headers)
    
    if r.status_code == 200:
        print(" 成功获取 {} ".format(url))
        #qiushi_tag_121983966 > a:nth-child(2) > div:nth-child(1)
        # 使用pyquery 解析网页， 获取下一页链接
        doc = pq(r.content)
        
        for content in doc('#content-left  .content  span'):
            print(content.text_content())

if __name__ == '__main__':
    qiubaispider()